###作业二.用类实现斐波拉契数列，编写一个自定义的迭代器
class fb(object):
    # 进行初始化
    def __init__(self):
        self.list=[]
        self.count=0
    #定义__iter__()方法，返回本身
    def __iter__(self):
        return self
    #定义__next__方法，让其进行迭代
    def __next__(self):
        if len(self.list)==0:
            self.list.append(0)
        elif len(self.list) == 1:
            self.list.append(1)
        else:
            #得到下一个数，取列表最后两个数相加
            result=self.list[-1]+self.list[-2]
            self.list.append(result)
        return self.list

a=fb()
#查看a的__iter__()方法返回是否是a本身
print(type(a),type(a.__iter__()))  #查看a和a__iter__()类型
print(a,a.__iter__())     #查看a和a__iter__()
print(a.__next__())
print(a.__next__())
print(a.__next__())
print(a.__next__())
print(a.__next__())
print(a.__next__())
